{extend name="main" /}

{block name="body"}
<div class="layui-card layadmin-header">
    <div class="layui-breadcrumb" lay-filter="breadcrumb" style="visibility: visible;">
        <a href="{:url('index/home',array('webid'=>$web['id']))}">{$web.title}</a>
        <a href="{:url('module/index',array('webid'=>$web.id,'moduleid'=>$module.moduleid))}">{$module.name}</a>
        <a><cite>编辑</cite></a>
    </div>
</div>
<div class="layui-form" lay-filter="layuiadmin-app-form-list" id="layuiadmin-app-form-list" style="padding: 20px 30px 0 0;">
    <form action="{:request()->url()}" method="post" class="xn_ajax2" data-type="open">
        <div class="layui-form-item">
            <label class="layui-form-label">所属分类</label>
            <div class="layui-input-inline">
                <select name="typeid" id="typeid">
                    <option value="0">选择类型</option>
                    {foreach name="categorylist" item="vo"}
                        <option value="{$vo.catid}" {if $vo.catid==$data.catid}selected{/if}>{$vo.catname}</option>
                        {foreach name="vo.children" item="vo2"}
                        <option value="{$vo2.catid}" {if $vo2.catid==$data.catid}selected{/if}>├&nbsp;{$vo2.catname}</option>
                        {/foreach}
                    {/foreach}
                </select>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">{$module.name}标题</label>
            <div class="layui-input-block">
                <input type="text" name="title" lay-verify="required" placeholder="" autocomplete="off" class="layui-input" value="{$data.title}">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">关键词</label>
            <div class="layui-input-block">
                <input type="text" name="keywords" placeholder="" autocomplete="off" class="layui-input" value="{$data.tag}">
            </div>
        </div>
        {foreach name="fields" item="vo"}
        {switch name="vo.html"}
            {case value="text"}
            <div class="layui-form-item">
                <label class="layui-form-label">{$vo.title}</label>
                <div class="layui-input-block">
                    <input type="text" name="{$vo.name}" placeholder="" autocomplete="off" class="layui-input" value="{$data[$vo.name]}">
                </div>
            </div>
            {/case}
            {case value="checkbox"}
            {php}$check_arr = explode(",",$data[$vo['name']]);{/php}
            <div class="layui-form-item">
                <label class="layui-form-label">{$vo.title}</label>
                <div class="layui-input-block">
                    {php}$arr = explode("\r\n",$vo['option_value']);{/php}
                    {foreach name="arr" item="val"}
                        {php}$v = explode("|",$val);{/php}
                        <input {if condition="in_array($v[0],$check_arr)"}checked{/if} type="checkbox" name="{$vo.name}[]" value="{$v[0]}" title="{:trim($v[0])}">
                    {/foreach}
                </div>
            </div>
            {/case}
        {/switch}
        {/foreach}
        <div class="layui-form-item layui-form-text">
            <label class="layui-form-label">{$module.name}简介</label>
            <div class="layui-input-block">
                <textarea name="description" class="layui-textarea">{$data.introduce}</textarea>
            </div>
        </div>
        <div class="layui-form-item layui-form-text">
            <label class="layui-form-label">{$module.name}内容</label>
            <div class="layui-input-block" id="tags">
                <blockquote class="layui-elem-quote layui-quote-nm">
                <div class="layui-inline">
                    <button type="button" class="layui-btn layui-btn-normal" style="background-color: #{:randColor()};">条件</button>
                </div>
                <div class="layui-inline">
                    <button type="button" class="layui-btn layui-btn-normal" style="background-color: #{:randColor()};">优势</button>
                </div>
                <div class="layui-inline">
                    <button type="button" class="layui-btn layui-btn-normal" style="background-color: #{:randColor()};">流程</button>
                </div>
                <div class="layui-inline">
                    <button type="button" class="layui-btn layui-btn-normal" style="background-color: #{:randColor()};">支持</button>
                </div>
                <div class="layui-inline">
                    <button type="button" class="layui-btn layui-btn-normal" style="background-color: #{:randColor()};">费用表格</button>
                </div>
                <div class="layui-inline">
                    <button type="button" class="layui-btn layui-btn-normal" style="background-color: #{:randColor()};">利润表格</button>
                </div>
                <div class="layui-inline">
                    <button type="button" class="layui-btn layui-btn-normal" style="background-color: #{:randColor()};">过渡段落</button>
                </div>
                <div class="layui-inline">
                    <button type="button" class="layui-btn layui-btn-normal" style="background-color: #{:randColor()};">复用段落</button>
                </div>
                <div class="layui-inline">
                    <button type="button" class="layui-btn layui-btn-normal" style="background-color: #{:randColor()};">图片</button>
                </div>
                </blockquote>
            </div>
            <div class="layui-input-block">
                <div class="layui-input-inline" style="width: 48%;">
                    <blockquote class="layui-elem-quote layui-quote-nm">
                        编辑内容：
                        <div class="layui-inline">
                            <button id="makeContent" type="button" class="layui-btn layui-btn-normal" style="background-color: #{:randColor()};">生成</button>
                        </div>
                        <div class="layui-inline">
                            <input id="dalei" type="text" class="layui-input" placeholder="大类" value="" style="width: 100px;">
                        </div>
                        <div class="layui-inline">
                            <input id="xiaolei" type="text" class="layui-input" placeholder="小类" value="" style="width: 100px;">
                        </div>
                        <div class="layui-inline">
                            <input id="xiangmu" type="text" class="layui-input" placeholder="项目" value="" style="width: 100px;">
                        </div>
                    </blockquote>
                    <textarea id="content_temp"></textarea>
                </div>
                <div class="layui-input-inline" style="width: 48%;">
                    <blockquote class="layui-elem-quote layui-quote-nm">
                        最终内容：
                        <div class="layui-inline">
                            <button type="button" class="layui-btn layui-btn-normal" style="background-color: #{:randColor()};">清空</button>
                        </div>
                    </blockquote>
                    <textarea name="content" id="content">{$data.content}</textarea>
                </div>
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-input-block">
                <button type="submit" lay-submit class="layui-btn">发布</button>
                <button type="reset" class="layui-btn layui-btn-primary">重置</button>
            </div>
        </div>
    </form>
</div>
{/block}
{block name="js"}
<!--编辑器-->
<script src="/static/admin/ueditor/ueditor.config.js"></script>
<script src="/static/admin/ueditor/ueditor.all.min.js"></script>
<script src="/static/admin/ueditor/lang/zh-cn/zh-cn.js"></script>
<script>
    var ue_temp = UE.getEditor('content_temp',{
        initialFrameWidth : '100%',// 设置编辑器宽度
        initialFrameHeight:400,// 设置编辑器高度
        autoHeightEnabled: false
    });
    var ue = UE.getEditor('content',{
        initialFrameWidth : '100%',// 设置编辑器宽度
        initialFrameHeight:400,// 设置编辑器高度
        autoHeightEnabled: false
    });

    var tags = $('#tags').find('button');
    $.each(tags,function(index,item){
        $(item).click(function(){
            var str = '[TAG:'+$(this).text()+']';
            ue_temp.focus();
            ue_temp.execCommand('inserthtml', str);
        });
    });
    $(function(){
        $('#makeContent').click(function(){
            var dalei = $('#dalei').val();
            var xiaolei = $('#dalei').val();
            var xiangmu = $('#dalei').val();
            var content = ue_temp.getContent();
            $.post("{:url('admin/ajax/makeContent',array('webid'=>$web.id))}",{dalei:dalei,xiaolei:xiaolei,xiangmu:xiangmu,content:content},function(res){
                if(res.status){
                    ue.ready(function() {
                        ue.setContent(res.data);
                    });
                }
                // layer.msg(res.msg,{time:1500});
            });
       });
    });
</script>
{/block}
